import java.sql.*;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by 22kon on 2016/12/5.
 * Test for jdbc from
 * http://blog.csdn.net/sakura_yuan/article/details/51730493
 */
public class TestDrive {
    Connection connection = null;
    Statement statement = null;
    ResultSet resultSet = null;
    public String[] getAddress() throws SQLException{
        String sql = null;
        String url = "jdbc:mysql://localhost:3306/Emails?characterEncoding=utf8&useSSL=false";
        System.out.println("*");
        List<String> list = null;
        //try {
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
            connection = DriverManager.getConnection(url, "root", "22kon");
            connection.setAutoCommit(false);
            statement = connection.createStatement();
            sql = new String("Select * from Emails");
            resultSet = statement.executeQuery(sql);
            connection.commit();
            connection.setAutoCommit(true);
            list = new ArrayList<String>();
            while (resultSet.next()) {
                list.add(resultSet.getString(2));
            }
            int addressNum = list.size();
            String[] address = new String[addressNum];
            if (list != null &addressNum>0) {
                for (int i = 0; i < list.size(); i++) {
                    address[i] = list.get(i);
                    System.out.println(address[i]);
                }
            }
        return address;
    }
}
